/*
 * ThreadKlasse2.java
 *
 * Created on 6 maart 2008, 19:17
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package racer.client.network.threads;
import java.io.*;
import java.net.*;
import racer.client.data.PositionMessage;
import racer.client.network.*;
import racer.client.network.NetworkThreadManager;
/**
 *
 * @author Lieven
 */
public class GoingToServerThread implements Runnable {
    //PositionMessage mess;
    /** Creates a new instance of ThreadKlasse2 */
NetworkThreadManager ouder;   
 
    public GoingToServerThread(NetworkThreadManager t){
        ouder= t;

    }
    //voorlopig enkel voor chat gebruikt aangezien de posities meteen verzonden worden
    //vanuit de main thread (na het painten van de positie bij deze client)
   public void run() {		
		
	// Keep on reading from the socket till we receive the "Bye" from the server,
	// once we received that then we want to break.


	// If everything has been initialized then we want to write some data
	// to the socket we have opened a connection to on port port_number 
	
        if (ouder.clientSocket != null && ouder.os != null && ouder.is != null) {
            try {
		
		// Create a thread to read from the server
		
                   
		while (!ouder.closed) {
			String msg = ouder.inputLine.readLine();
	        //ouder.os.println(ouder.inputLine.readLine());
			if (msg != null)
				ouder.sendChatMessageToServer(2,msg);
	        //ouder.mess.setChatMessage(15,20.3,25.6,50);

		}
		
		// Clean up:
		// close the output stream
		// close the input stream
		// close the socket
		
		ouder.os.close();
		ouder.is.close();
		ouder.clientSocket.close();   
            } catch (IOException e) {
                System.err.println("IOException:  " + e);
            }
        }                    
   }            
            
 }   


